package invest.data;

import invest.pojo.datapojo.KlineHistory;
import invest.pojo.datapojo.Stock;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.*;

public class HKtest {
    int min = 400;
    int max = 4000;
    ExecutorService es = new ThreadPoolExecutor(min, max,
            60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
    static SortedSet<Stock> strings = new TreeSet(new Comparator<Stock>() {
        @Override
        public int compare(Stock o1, Stock o2) {
            return o1.getTurnoverRate()-o2.getTurnoverRate()>=0? -1 : 1;
        }
    });
    static SortedSet<Stock> stockset = (SortedSet)Collections.synchronizedSortedSet(strings);
    public static void main(String[] args) throws IOException {
        DataFactory dataFactory = new DataFactory();
        List<Stock> stockListdata = (List<Stock>) dataFactory.getData(DataEnum.USSTOCKREALTIME);
        long a = System.currentTimeMillis();
        for (int i = 0; i < stockListdata.size(); i++) {
            System.out.println(i);
            Stock stock = stockListdata.get(i);
            String code = stock.getSymbol();
            DataFactory dataFactory1 = new DataFactory(code);
            List<KlineHistory> klineHistories = (List<KlineHistory>) dataFactory1.getData(DataEnum.HKUSSTOCKKLINE);
            if (klineHistories==null ||klineHistories.size() < 4) {
                continue;
            }
            Double todayRiseRange = (klineHistories.get(0).getOpen() - klineHistories.get(1).getClose()) / klineHistories.get(1).getClose();
            Double yesterDayRiseRange = (klineHistories.get(1).getOpen() - klineHistories.get(2).getClose()) / klineHistories.get(2).getClose();
            Double yesterDayChangeRate = klineHistories.get(1).getTurnoverrate();
            if (yesterDayChangeRate == null) {
                continue;
            }
            Double yesterDaydiffer = klineHistories.get(1).getClose() - klineHistories.get(1).getOpen();
            boolean dayu = (todayRiseRange - yesterDayRiseRange) > 0;
            boolean yang = yesterDaydiffer > 0;
            boolean change = yesterDayChangeRate > 3;
            if (dayu && yang ) {
                strings.add(stock);
            }
        }
               Iterator<Stock> iterator = stockset.iterator();
        for (int i = 0; i < 50; i++) {
            System.out.println(iterator.next().getName());;
        }
        long b=System.currentTimeMillis();
        System.out.println((b-a)/1000);
    }

    class Exe extends Thread {

        private Stock stock;
        public Exe(Stock stock) {
            this.stock = stock;
        }

        @Override
        public void run() {

        }
    }
}
